package com.gitee.starblues.grape.core.builder;

import com.gitee.starblues.grape.core.domain.dto.rebate.RebateOrderDto;
import com.gitee.starblues.grape.core.domain.user.RebateOrder;
import com.gitee.starblues.grape.core.enums.RebateOrderStatusEnum;
import com.gitee.starblues.grape.repository.databases.entity.RebateOrderPo;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class RebateOrderBuilder {
	public static RebateOrder build(RebateOrderPo source) {
		RebateOrder target = new RebateOrder();
		target.setSubmitDate(source.getInsertedTime());
		BeanUtils.copyProperties(source, target);
		return target;
	}

	public static List<RebateOrder> build(List<RebateOrderPo> source) {
		List<RebateOrder> target = new ArrayList<RebateOrder>();
		for (RebateOrderPo po : source) {
			target.add(RebateOrderBuilder.build(po));
		}
		return target;
	}
	
	public static RebateOrderPo build(RebateOrder source) {
		RebateOrderPo target = new RebateOrderPo();
		BeanUtils.copyProperties(source, target);
		return target;
	}
	
	public static RebateOrder build(RebateOrderDto source, String userId) {
		RebateOrder target = new RebateOrder();
		BeanUtils.copyProperties(source, target);
		target.setSubmitDate(new Date());
		target.setStatus(RebateOrderStatusEnum.PRE_CHECK.getCode());
		target.setUserId(userId);
		return target; 
	}
	

}
